package com.njupt.simulation.utils;

public class CoordinateTransform {
    /**
     *
     * @param lon 经度
     * @param lat 纬度
     * @param alt 高度
     * @return results  地心地固坐标X,Y,Z存储在数组中
     */
    public static double[] coordinatetransform(double lon, double lat, double alt) {
        //List<double[]> results = new ArrayList<>();//使用List存储计算结果
            //lon经度    lat纬度     alt高度
            //f为基准椭球体的极扁率
            double f = 1 / 298.25722;
            //a为基准椭球体的长半径
            double a = 6378.137;
            //N为基准椭球体的曲率半径
            double N;
            double sin_lat, cos_lat, cos_lon, sin_lon, X, Y, Z, b;
            double lon1 = (lon * Math.PI) / 180;
            double lat1 = (lat * Math.PI) / 180;
            sin_lat = Math.sin(lat1);
            sin_lon = Math.sin(lon1);
            cos_lat = Math.cos(lat1);
            cos_lon = Math.cos(lon1);
            b = Math.sqrt(1 - f * (2 - f) * sin_lat * sin_lat);
            N = a / b;
            X = (N + alt) * cos_lat * cos_lon;
            Y = (N + alt) * cos_lat * sin_lon;
            Z = (N * (1 - f) * (1 - f) + alt) * sin_lat;

            double[] transformedCoord = {X,Y,Z};//将一组计算结果存储在数组中
        return transformedCoord;
        }
    public static void main(String[] args) {
        // 定义顶点 A 和 B 的坐标

        double[] earthA= coordinatetransform(147.744,-0.102,0.0655);
        double[] satA= coordinatetransform(147.753,0.134,35786);
        double[] satB= coordinatetransform(149.753,0.134,35786);
        double[] earthB= coordinatetransform(149.030,0.160,0.0621);
        double[] satC= coordinatetransform(146.253,0.134,35786);
        double[] earthC= coordinatetransform(-146.024,0.238,0.0679);
        // 打印结果
        System.out.println("地球站AX：" + earthA[0]);System.out.println("地球站AY：" + earthA[1]);System.out.println("地球站AZ：" + earthA[2]);
        System.out.println("卫星AX：" + satA[0]);System.out.println("卫星AY：" + satA[1]);System.out.println("卫星AZ：" + satA[2]);
        System.out.println("卫星BX：" + satB[0]);System.out.println("卫星BY：" + satB[1]);System.out.println("卫星BZ：" + satB[2]);
        System.out.println("地球站BX：" + earthB[0]);System.out.println("地球站BY：" + earthB[1]);System.out.println("地球站BZ：" + earthB[2]);
        System.out.println("卫星CX：" + satC[0]);System.out.println("卫星CY：" + satC[1]);System.out.println("卫星CZ：" + satC[2]);
        System.out.println("地球站CX：" + earthC[0]);System.out.println("地球站CY：" + earthC[1]);System.out.println("地球站CZ：" + earthC[2]);
    }
}
